#! /usr/bin/perl -w
package Message;

use strict;
use POSIX qw(WNOHANG);
use Constants;

our $VERSION = 1.00;

sub new{
   my ($class) = @_; 
   my $self = { 
      _type => undef,
		_target_id=>undef,
      _executable => undef,
      _parameter => undef,
		_logfile => undef
   };  
   bless $self;
   return $self;
}

sub init{
   my ($self, $msg_str) = @_; 

	$_ = $msg_str;

   if(m/^$COMMAND_TAG(.*)/) {   
      my @content = split /;/, $1; 
		$self->{_type} = $MSG_COMMAND_TYPE;
		$self->{_target_id} = $content[0] if defined($content[0]);
		$self->{_logfile} = $content[1] if defined($content[1]);
		$self->{_executable} = $content[2] if defined($content[2]);
 		if(defined($content[3])) {
			my @parameters = split /,/, $content[3];
			$self->{_parameter} = @parameters;
		}
   } elsif(m/^$STATUS_TAG(.*)/) {   
      my @content = split /:/, $1; 
		$self->{_type} = $MSG_STATUS_TYPE;
		#for Status: executable hold the message content
		$self->{_target_id} = $content[0] if defined($content[0]);
		$self->{_executable} = $content[1] if defined($content[1]);
		shift(@content);
		shift(@content);
		$self->{_parameter} = join(":", @content);
   } else {   
		$self->{_type} = $MSG_UNKNOWN_TYPE;
   }   
}

sub get_type {
	my ($self) = @_;
	return $self->{_type};
}

sub get_executable {
	my ($self) = @_;
	return $self->{_executable};
}

sub get_parameter {
	my ($self) = @_;
	return $self->{_parameter};
}

sub get_target_id {
	my ($self) = @_;
	return $self->{_target_id};
}

sub get_logfile {
	my ($self) = @_;
	return $self->{_logfile};
}
